package com.fc.test.service;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.ForeSchoolMapper;
import com.fc.test.model.auto.ForeSchool;
import com.fc.test.model.auto.ForeSchoolExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;

/**
 *  ForeSchoolService
 * @Title: ForeSchoolService.java 
 * @Package com.fc.test.service 
 * @author fuce_自动生成
 * @email 115889198@qq.com
 * @date 2020-04-19 16:12:08  
 **/
@Service
public class ForeSchoolService implements BaseService<ForeSchool, ForeSchoolExample>{
	@Autowired
	private ForeSchoolMapper foreSchoolMapper;
	
      	   	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<ForeSchool> list(Tablepar tablepar,String name){
	        ForeSchoolExample testExample=new ForeSchoolExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andImageLike("%"+name+"%");
	        }

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<ForeSchool> list= foreSchoolMapper.selectByExample(testExample);
	        PageInfo<ForeSchool> pageInfo = new PageInfo<ForeSchool>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=Convert.toListStrArray(ids);
			ForeSchoolExample example=new ForeSchoolExample();
			example.createCriteria().andIdIn(lista);
			return foreSchoolMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public ForeSchool selectByPrimaryKey(String id) {
				
			return foreSchoolMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(ForeSchool record) {
		return foreSchoolMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(ForeSchool record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return foreSchoolMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(ForeSchool record, ForeSchoolExample example) {
		
		return foreSchoolMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(ForeSchool record, ForeSchoolExample example) {
		
		return foreSchoolMapper.updateByExample(record, example);
	}

	@Override
	public List<ForeSchool> selectByExample(ForeSchoolExample example) {
		
		return foreSchoolMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(ForeSchoolExample example) {
		
		return foreSchoolMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(ForeSchoolExample example) {
		
		return foreSchoolMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param foreSchool
	 * @return
	 */
	public int checkNameUnique(ForeSchool foreSchool){
		ForeSchoolExample example=new ForeSchoolExample();
		example.createCriteria().andImageEqualTo(foreSchool.getImage());
		List<ForeSchool> list=foreSchoolMapper.selectByExample(example);
		return list.size();
	}


}
